package ui.helpers;

import core.DatabaseTable;
import core.TableColumn;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 * The class is used to transform the {@link DatabaseTable} into a single-column JTable.
 * Due to naming conventions of the JTable, the <code>_columnName</code> field of the class
 * is actually the TableName of the {@link DatabaseTable}, and the <code>_rows</code> are actually the columns of the {@link DatabaseTable}
 *
 * @author Sakis Vtdk <sakis.vtdk@gmail.com>
 */
public class DbTableViewModel extends AbstractTableModel
{

	public DbTableViewModel(DatabaseTable dbTable)
	{
		this._columnName = dbTable.getName();

		for(TableColumn column : dbTable.getColumns())
		{
			this._rows.add(column.getName() +" ( "+ column.getDataType(true) +" )");
		}
		this._rows.add(NEW_COLUMN_COMMAND);
	}

	@Override
	public int getRowCount() 
	{
		return this._rows.size();
	}

	@Override
	public int getColumnCount() 
	{
		return 1;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) 
	{
		return this._rows.get(rowIndex);
	}

	@Override
	public String getColumnName(int column)
	{
		return this._columnName;
	}

	private String _columnName; 
	private ArrayList<String> _rows = new ArrayList<String>();

	public static final String NEW_COLUMN_COMMAND = "Add Column";
	
}
